package org.osflash.signals.natives;

import asunit.asserts.*;
import flash.display.Sprite;
import flash.events.Event;

class AmbiguousRelationshipInNativeSignalTest {

	var target : Sprite;
	var instance : NativeSignal;
	@:meta(Before())
	public function setUp() : Void {
		target = new Sprite();
		instance = new NativeSignal(target, Event.CHANGE);
	}

	@:meta(After())
	public function tearDown() : Void {
		instance = null;
	}

	@:meta(Test(expects="flash.errors.IllegalOperationError"))
	public function add_then_addOnce_throws_error() : Void {
		instance.add(failIfCalled);
		instance.addOnce(failIfCalled);
	}

	@:meta(Test(expects="flash.errors.IllegalOperationError"))
	public function addOnce_then_add_should_throw_error() : Void {
		instance.addOnce(failIfCalled);
		instance.add(failIfCalled);
	}

	@:meta(Test())
	public function add_then_add_should_not_throw_error() : Void {
		instance.add(failIfCalled);
		instance.add(failIfCalled);
		assertEquals(1, instance.numListeners);
	}

	@:meta(Test())
	public function addOnce_then_addOnce_should_not_throw_error() : Void {
		instance.addOnce(failIfCalled);
		instance.addOnce(failIfCalled);
		assertEquals(1, instance.numListeners);
	}

	function failIfCalled(event : Event) : Void {
		fail("if this listener is called, something horrible is going on");
	}

}

